/**
 * Created by zhangqingxi on 2017-04-06.
 */
var modelPath = ROOT_PATH + '/emergency/supplies/';


//初始化部门
function initDept() {

    $('#deptId').combotree({
        url: findDept,
        required:true,
        editable:false,
        prompt:'请选择'
    });
}

//初始化负责人
function initUser() {
    $("#chargePersonName").textbox({
        editable:false,
        iconWidth: 22,
        icons: [{
            iconCls: 'icon-add',
            handler: function (e) {
                add_userInfo_func();
            }
        }, {
            iconCls: 'icon-remove',
            handler: function (e) {
                $(e.data.target).textbox('clear');
                $('#chargePersonId').val('');

            }
        }]
    });
}
function add_userInfo_func() {
    WindowManager.openLayer({
        type: 2,
        title: '选择人员信息',
        area: ['1150px', '70%'],
        content: ROOT_PATH + '/permission/user/simpleList.shtml?isMulti=0',
        callBack: function (data) {//窗口关闭后的回调函数
            var id = data[0].id;
            var name = data[0].realName;

            $('#chargePersonId').val(id);
            $('#chargePersonName').textbox('setValue', name);

        }
    });

}
//是否过期
function initIsOverdue() {
    initYesOrNo('#isOverdue');
    $('#isOverdue').combobox({
        onSelect:function (record) {
            if(record.id===0){
                $('#overdue_div').form('disableValidation')
            }else if (record.id===1){
                $('#overdue_div').form('enableValidation')
            }
        }
    });
}
//存放点
function  initStoragePoint() {
    $('#storagePointId').combogrid({
        required: true,
        editable: false,
        readonly: false,
        panelWidth: 900,
        prompt: '请选择',
        idField: 'id',
        textField: 'name',
        queryParams: {
            sort: 'd.addTime',
            order: 'desc'
        },
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        sortOrder: true,
        striped: true,
        url: findStoragePoint,
        columns: [[
            {field: 'name', title: '存放点名称', width: 10},
            {field:'typeName',title:'存放点类型',width:10},
            {field:'reserveClassificationName',title:'储备库分类',width:10},
            {field:'deptName',title:'所属单位',width:10},
        ]]
    });
}
//初始化物资类型大类
function initBigType() {
    $('#bigTypeId').combobox({
        url:dictionaryByCode+suppliesBigType,
        prompt:'请选择',
        required:true,
        editable:false,
        valueField:'id',
        textField:'text',
        onSelect:function (record) {
            initMiddleType(record.code);
        },
        onChange:function () {
            resetCombobox('#smallTypeId');
            $('#middleTypeId').combobox({
                value:''
            });
            $('#smallTypeId').combobox({
                value:''
            });
        }
    });
}
//物资类型中类
function initMiddleType(code) {
    $('#middleTypeId').combobox({
        url:dictionaryByDatas,
        queryParams:{
            data1:code
        },
        prompt:'请选择',
        required:true,
        editable:false,
        valueField:'id',
        textField:'text',
        onSelect:function (record) {
            initSmallType(record.code);
        },
        onChange:function () {
            $('#smallTypeId').combobox({
                value:''
            });
        }

    });
}
//物资类型中类
function initSmallType(code) {
    $('#smallTypeId').combobox({
        url:dictionaryByDatas,
        queryParams:{
            data1:code
        },
        prompt:'请选择',
        required:true,
        editable:false,
        valueField:'id',
        textField:'text'

    });
}